-
Notifications
You must be signed in to change notification settings - Fork 252
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Limit debug logs to 4096 bytes on vercel to avoid errors #1598
Conversation
🦋 Changeset detectedLatest commit: c092747 The changes in this PR will be included in the next version bump. Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✅ Great news! Jit hasn't found any security issues in your PR. Good Job! 🏆
@@ -1,5 +1,7 @@ | |||
// TODO: Replace with a more sophisticated logging solution | |||
|
|||
import truncate from 'truncate-utf8-bytes'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe we intentionally try to mitigate usage of 3p dependencies in our packages. We can inline this pretty easily using TextEncoder
and TextDecoder
:
function truncate(str: string, maxLength: number) {
const encoder = new TextEncoder();
const decoder = new TextDecoder('utf-8');
const encodedString = encoder.encode(str);
const truncatedString = encodedString.slice(0, maxLength);
// return the truncated string, removing any replacement characters that result from partially truncated characters
return decoder.decode(truncatedString).replace(/\uFFFD/g, '');
}
(ref)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Happy to shift over to this, but I was reluctant to do so initially since it doesn't handle multi-byte characters, where the library I included does, and is hardly any more code overall. We could copy-paste the 3p library code too, but that seems a little silly
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jescalan The above sort of handles the multi-byte characters by stripping out the leftovers if they get split. I see what you're saying, but let's inline for now and we can revisit the stance on dependencies as a team. The fact that our deps list is so short feels deliberate.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤷♂️ done!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! I think we need a patch
changeset here and then it's good to go. Nice work
96c773d
to
e14d271
Compare
e14d271
to
c092747
Compare
This PR has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Type of change
Packages affected
@clerk/clerk-js
@clerk/clerk-react
@clerk/nextjs
@clerk/remix
@clerk/types
@clerk/themes
@clerk/localizations
@clerk/clerk-expo
@clerk/backend
@clerk/clerk-sdk-node
@clerk/shared
@clerk/fastify
@clerk/chrome-extension
gatsby-plugin-clerk
build/tooling/chore
Description
npm test
runs as expected.npm run build
runs as expected.When deployed to Vercel, logs cannot exceed 4096 bytes, or no logs are displayed at all and the user gets an error instead. This PR truncates debug logs to 4096 bytes to ensure that they display correctly on Vercel.
Fixes JS-608